package com.huawei.appgallery.forum.section.view.widget.tips;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Path.Direction;
import android.graphics.Point;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.widget.FrameLayout;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import o.cab.c;
import o.cab.g;
import o.ContentManager;
import o.MinimumFactory;

public class BubbleLayout extends FrameLayout {
    private Paint ʻ;
    private Path ʽ;
    private Point ˊ;
    @Direction
    private int ˋ;
    private int ˎ;
    private int ˏ;
    private int ॱ;
    private RectF ॱॱ;
    private boolean ᐝ = MinimumFactory.getBoolValue(ContentManager.getInstant().getContext());

    public BubbleLayout(@NonNull Context context, @Nullable AttributeSet attributeSet) {
        super(context, attributeSet);
        ˋ(context, attributeSet);
    }

    private void ˋ(Context context, AttributeSet attributeSet) {
        TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, g.ʿ);
        int color = obtainStyledAttributes.getColor(g.ʽॱ, -1);
        int color2 = obtainStyledAttributes.getColor(g.ˈ, Color.parseColor("#999999"));
        int dimensionPixelSize = obtainStyledAttributes.getDimensionPixelSize(g.ʾ, (int) TypedValue.applyDimension(0, 4.0f, getResources().getDisplayMetrics()));
        this.ˎ = obtainStyledAttributes.getDimensionPixelSize(g.ˊˊ, 0);
        this.ˋ = obtainStyledAttributes.getInteger(g.ˊˋ, 4);
        this.ॱ = obtainStyledAttributes.getDimensionPixelOffset(g.ˋˊ, 0);
        this.ˏ = obtainStyledAttributes.getDimensionPixelOffset(g.ˊᐝ, 0);
        obtainStyledAttributes.recycle();
        this.ʻ = new Paint();
        this.ʻ.setAntiAlias(true);
        this.ʻ.setColor(color);
        this.ʻ.setShadowLayer((float) dimensionPixelSize, 0.0f, 0.0f, color2);
        this.ʽ = new Path();
        this.ॱॱ = new RectF();
        this.ˊ = new Point();
        setWillNotDraw(false);
        setLayerType(1, null);
    }

    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        if (this.ˊ.x > 0 && this.ˊ.y > 0) {
            switch (this.ˋ) {
                case 1:
                    ॱ(canvas);
                    return;
                case 2:
                    ˊ(canvas);
                    return;
                case 3:
                    ˎ(canvas);
                    return;
                case 4:
                    ˏ(canvas);
                    return;
                default:
                    return;
            }
        }
    }

    private void ॱ(Canvas canvas) {
        if (this.ॱ != 0) {
            this.ʽ.addRoundRect(this.ॱॱ, (float) this.ˎ, (float) this.ˎ, Direction.CCW);
            this.ʽ.moveTo((float) this.ˊ.x, (float) (this.ˊ.y - this.ॱ));
            this.ʽ.lineTo((float) (this.ˊ.x - this.ॱ), (float) this.ˊ.y);
            this.ʽ.lineTo((float) this.ˊ.x, (float) (this.ˊ.y + this.ॱ));
            this.ʽ.close();
            canvas.drawPath(this.ʽ, this.ʻ);
        }
    }

    private void ˊ(Canvas canvas) {
        if (this.ॱ != 0) {
            this.ʽ.addRoundRect(this.ॱॱ, (float) this.ˎ, (float) this.ˎ, Direction.CCW);
            this.ʽ.moveTo((float) (this.ˊ.x + this.ॱ), (float) this.ˊ.y);
            this.ʽ.lineTo((float) this.ˊ.x, (float) (this.ˊ.y - this.ॱ));
            this.ʽ.lineTo((float) (this.ˊ.x - this.ॱ), (float) this.ˊ.y);
            this.ʽ.close();
            canvas.drawPath(this.ʽ, this.ʻ);
        }
    }

    private void ˎ(Canvas canvas) {
        if (this.ॱ != 0) {
            this.ʽ.addRoundRect(this.ॱॱ, (float) this.ˎ, (float) this.ˎ, Direction.CCW);
            this.ʽ.moveTo((float) this.ˊ.x, (float) (this.ˊ.y - this.ॱ));
            this.ʽ.lineTo((float) (this.ˊ.x + this.ॱ), (float) this.ˊ.y);
            this.ʽ.lineTo((float) this.ˊ.x, (float) (this.ˊ.y + this.ॱ));
            this.ʽ.close();
            canvas.drawPath(this.ʽ, this.ʻ);
        }
    }

    private void ˏ(Canvas canvas) {
        if (this.ॱ != 0) {
            this.ʽ.addRoundRect(this.ॱॱ, (float) this.ˎ, (float) this.ˎ, Direction.CCW);
            this.ʽ.moveTo((float) (this.ˊ.x + this.ॱ), (float) this.ˊ.y);
            this.ʽ.lineTo((float) this.ˊ.x, (float) (this.ˊ.y + this.ॱ));
            this.ʽ.lineTo((float) (this.ˊ.x - this.ॱ), (float) this.ˊ.y);
            this.ʽ.close();
            canvas.drawPath(this.ʽ, this.ʻ);
        }
    }

    protected void onSizeChanged(int i, int i2, int i3, int i4) {
        super.onSizeChanged(i, i2, i3, i4);
        switch (this.ˋ) {
            case 1:
                this.ॱॱ.left = (float) this.ॱ;
                this.ॱॱ.top = 0.0f;
                this.ॱॱ.right = (float) i;
                this.ॱॱ.bottom = (float) i2;
                this.ˊ.x = this.ॱ;
                this.ˊ.y = i2 / 2;
                break;
            case 2:
                this.ॱॱ.left = 0.0f;
                this.ॱॱ.top = (float) this.ॱ;
                this.ॱॱ.right = (float) i;
                this.ॱॱ.bottom = (float) i2;
                this.ˊ.x = i / 2;
                this.ˊ.y = this.ॱ;
                break;
            case 3:
                this.ॱॱ.left = 0.0f;
                this.ॱॱ.top = 0.0f;
                this.ॱॱ.right = (float) (i - this.ॱ);
                this.ॱॱ.bottom = (float) i2;
                this.ˊ.x = i - this.ॱ;
                this.ˊ.y = i2 / 2;
                break;
            case 4:
                this.ॱॱ.left = 0.0f;
                this.ॱॱ.top = 0.0f;
                this.ॱॱ.right = (float) i;
                this.ॱॱ.bottom = (float) (i2 - this.ॱ);
                this.ˊ.x = i / 2;
                this.ˊ.y = i2 - this.ॱ;
                break;
        }
        if (this.ˏ != 0) {
            ˎ();
        }
    }

    private void ˎ() {
        switch (this.ˋ) {
            case 1:
            case 3:
                ˋ();
                return;
            case 2:
            case 4:
                ˏ();
                return;
            default:
                return;
        }
    }

    private void ˋ() {
        int height = (int) this.ॱॱ.height();
        if (this.ˏ > height - getResources().getDimensionPixelSize(c.ˊ)) {
            this.ˊ.y = height / 2;
        } else if (this.ᐝ) {
            this.ˊ.y = height - this.ˏ;
        } else {
            this.ˊ.y = this.ˏ;
        }
    }

    private void ˏ() {
        int width = (int) this.ॱॱ.width();
        if (this.ˏ > width - getResources().getDimensionPixelSize(c.ˊ)) {
            this.ˊ.x = width / 2;
        } else if (this.ᐝ) {
            this.ˊ.x = width - this.ˏ;
        } else {
            this.ˊ.x = this.ˏ;
        }
    }

    public void setTriangleOffset(int i) {
        this.ˏ = i;
        ˎ();
        invalidate();
    }

    public void setDirection(int i) {
        this.ˋ = i;
        ॱ();
        invalidate();
    }

    private void ॱ() {
        int dimensionPixelSize = getResources().getDimensionPixelSize(c.ˊ);
        switch (this.ˋ) {
            case 1:
                setPadding(dimensionPixelSize, 0, 0, 0);
                return;
            case 2:
                setPadding(0, dimensionPixelSize, 0, 0);
                return;
            case 3:
                setPadding(0, 0, dimensionPixelSize, 0);
                return;
            case 4:
                setPadding(0, 0, 0, dimensionPixelSize);
                return;
            default:
                return;
        }
    }
}
